package com.gz.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping(value = "/user")
@Controller
public class UserHandler {

    //method = RequestMethod.POST表示必须接收的是post请求才行
    //等价于@PostMapping(value = "/buy")
    //不写默认get和post都可以
    @RequestMapping(value = "/buy",method = RequestMethod.POST)
//    @PostMapping(value = "/buy")
    public String buy(){
        System.out.println("购买商品");
        return "success";
    }


    /**
     *1.params = "bookId"表示请求目标方法时，必须给一个bookId参数，值没有限定(如果没设值)
     *2.search(String bookId)表示请求目标时携带的bookId参数的值赋给String bookId
     */
    @RequestMapping(value = "/find",params = "bookId",method = RequestMethod.GET)
    public String search(String bookId){
        System.out.println("查询书籍 bookId="+bookId);
        return "success";
    }

    @RequestMapping(value = "/reg/{username}/{userid}")
    public String register(@PathVariable("username")String username,
                           @PathVariable("userid")String userid){
        System.out.println("接收到的参数"+username+","+userid);
        return "success";
    }


}
